package com.chapter.sample;

import com.chapter.sample.dao.UserDao;
import com.chapter.sample.service.UserService;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

public class BeanFactoryTest {
    public static void main(String[] args) {

        //创建工厂
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

        //创建一个读取器（xml）
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);

        //读取配置文件给工厂
        reader.loadBeanDefinitions("application.xml");

        //根据id获取Bean实例对象
        UserService userService = (UserService) beanFactory.getBean("userService");
        //System.out.println(userService);

        UserDao userDao = (UserDao) beanFactory.getBean("userDao");
        //System.out.println(userDao);

    }
}